package com.abbas.smartCity.ui.findJob;

import android.content.Context;
import android.view.View;
import android.widget.Button;

import com.abbas.smartCity.R;
import com.abbas.smartCity.adapter.ListCommAdapter;
import com.abbas.smartCity.base.BaseFragment;
import com.abbas.smartCity.bean.findJob.PostHistoryList;
import com.abbas.smartCity.retroft.ICallback;
import com.abbas.smartCity.view.MListView;

import retrofit2.Call;


public class HistoryDeliverFragment extends BaseFragment {

    private MListView lv;
    private Button loadmore;

    private Integer pageNum = 1;
    private Integer pageSize = 10;
    private ListCommAdapter<PostHistoryList.RowsBean, ListCommAdapter.ParkingHistoryHolder> listAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_history_deliver;
    }

    @Override
    protected void initView() {
        lv = (MListView) rootView.findViewById(R.id.lv);
        loadmore = (Button) rootView.findViewById(R.id.loadmore);
    }

    @Override
    protected void initData() {
        getList();
    }

    @Override
    protected void initEvent() {
        loadmore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pageNum++;
                getList();
            }
        });
    }

    private void getList() {
        api.getHistoryPost(pageNum, pageSize).enqueue(new ICallback<PostHistoryList>() {
            @Override
            public void onSuccess(Call<PostHistoryList> call, PostHistoryList data) {
                if (listAdapter == null) {
                    listAdapter = new ListCommAdapter<PostHistoryList.RowsBean, ListCommAdapter.ParkingHistoryHolder>(
                            data.getRows(),
                            ListCommAdapter.ParkingHistoryHolder.class,
                            R.layout.parking_history_item
                    ) {
                        @Override
                        protected void show(PostHistoryList.RowsBean item, View convertView, ParkingHistoryHolder viewHolder, int position, Context context) {
                            viewHolder.name.setText(item.getPostName());
                            viewHolder.tag1.setText("公司:"+item.getCompanyName());
                            viewHolder.tag2.setText("薪资:"+item.getMoney());
                            viewHolder.tag3.setText("投递时间:"+item.getSatrTime());
                        }
                    };
                    lv.setAdapter(listAdapter);
                } else {
                    listAdapter.append(data.getRows());
                }
            }
        });
    }
}